package com.zhu.ttwords.presenter;

import android.content.Context;
import android.content.SharedPreferences;

import com.zhu.ttwords.TTWORDS;
import com.zhu.ttwords.common.DBTool;
import com.zhu.ttwords.view.activity.ILoginActivity;

/**
 * Created by KnightYe on 2015/4/4.
 */
public class LoginPresenter {
    ILoginActivity activity;
    Context context;

    public LoginPresenter(Context context, ILoginActivity activity) {
        this.activity = activity;
        this.context = context;
    }

    public void login() {
        activity.loginSuccess();
    }

    public void regist() {

    }

    public void forgetPassword() {

    }

    /**
     * 加载数据库,初始化。
     */
    public void init() {
        checkDataBase();
        activity.loadComplate();
    }

    /**
     * 数据库检查
     */
    private void checkDataBase() {
        // 判断数据库目录存在
        DBTool.initDatabaseDir(context);
        // 判断数据库文件存在
        DBTool.initDatabaseFile(context);
        // 判断数据库版本
        if (TTWORDS.getAppSetting().getVersionCode() < TTWORDS.getVersionCode()) {
            DBTool.deleteDB();
            checkDataBase();
        }
    }


}
